home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qevent.h.z / qevent.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  9.0 KB  |  344 lines

  1. /****************************************************************************
  2. ** $Id: qevent.h,v 2.21 1998/07/03 00:09:32 hanord Exp $
  3. **
  4. ** Definition of event classes
  5. **
  6. ** Created : 931029
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QEVENT_H
  25. #define QEVENT_H
  26.  
  27. #ifndef QT_H
  28. #include "qwindowdefs.h"
  29. #include "qrect.h"
  30. #include "qstring.h"
  31. #endif // QT_H
  32.  
  33.  
  34. #define Event_None            0        // invalid event
  35. #define Event_Timer            1        // timer event
  36. #define Event_MouseButtonPress        2        // mouse button pressed
  37. #define Event_MouseButtonRelease    3        // mouse button released
  38. #define Event_MouseButtonDblClick   4        // mouse button double click
  39. #define Event_MouseMove            5        // mouse move
  40. #define Event_KeyPress            6        // key pressed
  41. #define Event_KeyRelease        7        // key released
  42. #define Event_FocusIn            8        // keyboard focus received
  43. #define Event_FocusOut            9        // keyboard focus lost
  44. #define Event_Enter           10        // mouse enters widget
  45. #define Event_Leave           11        // mouse leaves widget
  46. #define Event_Paint           12        // paint widget
  47. #define Event_Move           13        // move widget
  48. #define Event_Resize           14        // resize widget
  49. #define Event_Create           15        // after object creation
  50. #define Event_Destroy           16        // during object destruction
  51. #define Event_Show           17        // widget is shown
  52. #define Event_Hide           18        // widget is hidden
  53. #define Event_Close           19        // request to close widget
  54. #define Event_Quit           20        // request to quit application
  55. #define Event_Accel           30        // accelerator event
  56. #define Event_Clipboard           40        // internal clipboard event
  57. #define Event_SockAct           50        // socket activation
  58. #define Event_DragEnter           60        // drag moves into widget
  59. #define Event_DragMove           61        // drag moves in widget
  60. #define Event_DragLeave           62        // drag leaves or is cancelled
  61. #define    Event_Drop           63        // actual drop
  62. #define    Event_DragResponse       64        // drag accepted/rejected
  63. #define Event_ChildInserted       70        // new child widget
  64. #define Event_ChildRemoved       71        // deleted child widget
  65. #define Event_LayoutHint       72        // child min/max size changed
  66. #define Event_User         1000        // first user event id
  67.  
  68.  
  69. class QEvent                    // event base class
  70. {
  71. public:
  72.     QEvent( int type )
  73.     : t(type), posted(FALSE) {}
  74.    ~QEvent()            { if ( posted ) peErrMsg(); }
  75.     int      type()    const    { return t; }
  76. protected:
  77.     int      t;
  78.     bool  posted;
  79. private:
  80.     void  peErrMsg();
  81. };
  82.  
  83.  
  84. class QTimerEvent : public QEvent        // timer event
  85. {
  86. public:
  87.     QTimerEvent( int timerId )
  88.     : QEvent(Event_Timer), id(timerId) {}
  89.     int      timerId()    const    { return id; }
  90. protected:
  91.     int      id;
  92. };
  93.  
  94. #define Q_TIMER_EVENT(x)    ((QTimerEvent*)x)
  95.  
  96.  
  97. enum ButtonState {                // mouse/keyboard state values
  98.     NoButton        = 0x00,
  99.     LeftButton        = 0x01,
  100.     RightButton        = 0x02,
  101.     MidButton        = 0x04,
  102.     MouseButtonMask = 0x07,
  103.     ShiftButton        = 0x08,
  104.     ControlButton   = 0x10,
  105.     AltButton        = 0x20,
  106.     KeyButtonMask   = 0x38
  107. };
  108.  
  109. class QMouseEvent : public QEvent        // mouse event
  110. {
  111. public:
  112.     QMouseEvent( int type, const QPoint &pos, int button, int state )
  113.     : QEvent(type), p(pos), b(button),s((ushort)state) {}
  114.     const QPoint &pos() const    { return p; }
  115.     int       x()        const    { return p.x(); }
  116.     int       y()        const    { return p.y(); }
  117.     int       button()    const    { return b; }
  118.     int       state()    const    { return s; }
  119. protected:
  120.     QPoint p;
  121.     int       b;
  122.     ushort s;
  123. };
  124.  
  125. #define Q_MOUSE_EVENT(x)    ((QMouseEvent*)x)
  126.  
  127.  
  128. class QKeyEvent : public QEvent            // keyboard event
  129. {
  130. public:
  131.     QKeyEvent( int type, int key, int ascii, int state )
  132.     : QEvent(type), k((ushort)key), s((ushort)state), a((uchar)ascii),
  133.       accpt(TRUE) {}
  134.     int       key()    const    { return k; }
  135.     int       ascii()    const    { return a; }
  136.     int       state()    const    { return s; }
  137.     bool   isAccepted() const    { return accpt; }
  138.     void   accept()        { accpt = TRUE; }
  139.     void   ignore()        { accpt = FALSE; }
  140. protected:
  141.     ushort k, s;
  142.     uchar  a;
  143.     char   accpt;                // ### Qt 2.0: bool
  144. };
  145.  
  146. #define Q_KEY_EVENT(x)        ((QKeyEvent*)x)
  147.  
  148.  
  149. class QFocusEvent : public QEvent        // widget focus event
  150. {
  151. public:
  152.     QFocusEvent( int type )
  153.     : QEvent(type) {}
  154.     bool   gotFocus()    const { return type() == Event_FocusIn; }
  155.     bool   lostFocus()    const { return type() == Event_FocusOut; }
  156. };
  157.  
  158. #define Q_FOCUS_EVENT(x)    ((QFocusEvent*)x)
  159.  
  160.  
  161. class QPaintEvent : public QEvent        // widget paint event
  162. {
  163. public:
  164.     QPaintEvent( const QRect &paintRect )
  165.     : QEvent(Event_Paint), r(paintRect) {}
  166.     const QRect &rect() const    { return r; }
  167. protected:
  168.     QRect r;
  169. };
  170.  
  171. #define Q_PAINT_EVENT(x)    ((QPaintEvent*)x)
  172.  
  173.  
  174. class QMoveEvent : public QEvent        // widget move event
  175. {
  176. public:
  177.     QMoveEvent( const QPoint &pos, const QPoint &oldPos )
  178.     : QEvent(Event_Move), p(pos), oldp(oldPos) {}
  179.     const QPoint &pos()      const { return p; }
  180.     const QPoint &oldPos()const { return oldp;}
  181. protected:
  182.     QPoint p, oldp;
  183. };
  184.  
  185. #define Q_MOVE_EVENT(x)        ((QMoveEvent*)x)
  186.  
  187.  
  188. class QResizeEvent : public QEvent        // widget resize event
  189. {
  190. public:
  191.     QResizeEvent( const QSize &size, const QSize &oldSize )
  192.     : QEvent(Event_Resize), s(size), olds(oldSize) {}
  193.     const QSize &size()      const { return s; }
  194.     const QSize &oldSize()const { return olds;}
  195. protected:
  196.     QSize s, olds;
  197. };
  198.  
  199. #define Q_RESIZE_EVENT(x)    ((QResizeEvent*)x)
  200.  
  201.  
  202. class QCloseEvent : public QEvent        // widget close event
  203. {
  204. public:
  205.     QCloseEvent()
  206.     : QEvent(Event_Close), accpt(FALSE) {}
  207.     bool   isAccepted() const    { return accpt; }
  208.     void   accept()        { accpt = TRUE; }
  209.     void   ignore()        { accpt = FALSE; }
  210. protected:
  211.     bool   accpt;
  212. };
  213.  
  214. #define Q_CLOSE_EVENT(x)    ((QCloseEvent*)x)
  215.  
  216.  
  217. class QShowEvent : public QEvent        // widget show event
  218. {
  219. public:
  220.     QShowEvent(bool spontaneous)
  221.     : QEvent(Event_Show), spont(spontaneous) {}
  222.     bool spontaneous() const { return spont; }
  223. protected:
  224.     bool spont;
  225. };
  226.  
  227. #define Q_SHOW_EVENT(x)        ((QShowEvent*)x)
  228.  
  229.  
  230. class QHideEvent : public QEvent        // widget hide event
  231. {
  232. public:
  233.     QHideEvent(bool spontaneous)
  234.     : QEvent(Event_Hide), spont(spontaneous) {}
  235.     bool spontaneous() const { return spont; }
  236. protected:
  237.     bool spont;
  238. };
  239.  
  240. #define Q_HIDE_EVENT(x)        ((QHideEvent*)x)
  241.  
  242.  
  243. // this class is rather closed at the moment.  if you need to create
  244. // your own QDragMoveEvent objects, write to qt-bugs@troll.no and
  245. // we'll try to find a way to extend it so it covers your needs.
  246.  
  247. class QDragMoveEvent : public QEvent
  248. {
  249. public:
  250.     QDragMoveEvent( const QPoint& pos )
  251.     : QEvent(Event_DragMove), p(pos), accpt(FALSE), d(0),
  252.       rect( p,QSize( 1, 1 ) ) {}
  253.     const QPoint& pos() const   { return p; }
  254.     bool   isAccepted() const   { return accpt; }
  255.     void   accept()        { accpt = TRUE; }
  256.     void   ignore()        { accpt = FALSE; }
  257.     void   accept( const QRect & r) { accpt = TRUE; rect = r; }
  258.     void   ignore( const QRect & r) { accpt =FALSE; rect = r; }
  259.     QRect  answerRect() const { return rect; }
  260.     const char * format( int n = 0 );
  261.     bool provides( const char * );
  262.     QByteArray data( const char * );
  263. protected:
  264.     QDragMoveEvent( const QPoint& pos, int type )
  265.     : QEvent(type), p(pos), accpt(FALSE), d(0),
  266.       rect( p,QSize( 1, 1 ) ) {}
  267.     QPoint p;
  268.     bool   accpt;
  269.     void * d;
  270.     QRect rect;
  271. };
  272.  
  273. class QDragEnterEvent : public QDragMoveEvent
  274. {
  275. public:
  276.     QDragEnterEvent( const QPoint& pos ) :
  277.     QDragMoveEvent(pos, Event_DragEnter) { }
  278. };
  279.  
  280.  
  281. class QDragResponseEvent : public QEvent
  282. {
  283. public:
  284.     QDragResponseEvent( bool accepted )
  285.     : QEvent(Event_DragResponse), a(accepted) {}
  286.     bool   dragAccepted() const    { return a; }
  287. protected:
  288.     bool a;
  289. };
  290.  
  291.  
  292. class QDragLeaveEvent : public QEvent
  293. {
  294. public:
  295.     QDragLeaveEvent()
  296.     : QEvent(Event_DragLeave) {}
  297. };
  298.  
  299.  
  300. class QDropEvent : public QEvent
  301. {
  302. public:
  303.     QDropEvent( const QPoint& pos )
  304.     : QEvent(Event_Drop), p(pos), accpt(FALSE) {}
  305.     const QPoint &pos() const    { return p; }
  306.     bool   isAccepted() const    { return accpt; }
  307.     void   accept()        { accpt = TRUE; }
  308.     void   ignore()        { accpt = FALSE; }
  309.     QByteArray data( const char * );
  310. protected:
  311.     QPoint p;
  312.     bool   accpt;
  313. };
  314.  
  315.  
  316. class QChildEvent : public QEvent
  317. {
  318. public:
  319.     QChildEvent( int type, QWidget *child )
  320.     : QEvent(type), c(child) {}
  321.     QWidget *child() const    { return c; }
  322.     bool inserted() const { return t == Event_ChildInserted; }
  323.     bool removed() const { return t == Event_ChildRemoved; }
  324. protected:
  325.     QWidget *c;
  326. };
  327.  
  328.  
  329. class QCustomEvent : public QEvent        // user-defined event
  330. {
  331. public:
  332.     QCustomEvent( int type, void *data )
  333.     : QEvent(type), d(data) {}
  334.     void       *data()    const    { return d; }
  335. private:
  336.     void       *d;
  337. };
  338.  
  339.  
  340. #define Q_CUSTOM_EVENT(x)    ((QCustomEvent*)x)
  341.  
  342.  
  343. #endif // QEVENT_H
  344.